package com.fr.lintcode;

import java.util.ArrayList;
import java.util.List;

import org.junit.Test;

/**
*作者：furong
*日期：2017年1月13日
*时间：上午10:15:51
*/
public class Q112 {

    /**
     * @param ListNode head is the head of the linked list
     * @return: ListNode head of linked list
     */
    public static ListNode deleteDuplicates(ListNode head) {
        if (head == null) {
            return null;
        }
        ListNode parent = head;
        ListNode c = head;
        List<Integer> list = new ArrayList<>();
        list.add(head.val);
        while ((c = c.next) != null) {
            if (list.contains(c.val)) {
            } else {
                list.add(c.val);
                parent.next = c;
                parent = parent.next;
            }
        }
        parent.next = null;
        return head;
    }

    @Test
    public void testA() {
        ListNode head = new ListNode(1);
        ListNode l1 = new ListNode(1);
        ListNode l2 = new ListNode(2);
        ListNode l3 = new ListNode(2);
        ListNode l4 = new ListNode(3);
        ListNode l5 = new ListNode(3);
        ListNode l6 = new ListNode(4);
        ListNode l7 = new ListNode(4);
        ListNode l8 = new ListNode(1);
        head.next = l1;
        l1.next = l2;
        l2.next = l3;
        l3.next = l4;
        l4.next = l5;
        l5.next = l6;
        l6.next = l7;
        l7.next = l8;
        System.out.println(head);
        head = deleteDuplicates(head);
        System.out.println(head);
    }
}
